package com.rich.house.controller;

import com.rich.common.annotation.IngoreResponseAdvice;
import com.rich.common.entity.TbHouse;
import com.rich.common.result.ResultData;
import com.rich.house.service.HouseService;
import com.rich.house.vo.HouseSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;

/**
 * @Package: com.rich.house.controller
 * @Author: 张dy
 * @Date: Created in 2021/8/13 下午 7:34
 */
@RestController
@RequestMapping("/house")
public class HouseController {

    @Autowired
    private HouseService houseService;

    /**
     * 新房 二手房 出租房
     *
     * @param houseSearchVo
     * @return
     */
    @PostMapping("/getHouseList")
    public ResultData getHouseList(@RequestBody HouseSearchVo houseSearchVo) {
        return houseService.getHouseList(houseSearchVo);
    }


    /**
     * 房源管理(销售楼盘 房屋租赁)列表
     *
     * @Author: 张dy
     * @Date: 2021/8/16
     * @Param:
     */
    @PostMapping("/findHouseAll")
    public ResultData findHouseAll(@RequestBody HouseSearchVo houseSearchVo) {
        return houseService.findHouseAll(houseSearchVo);
    }

    /**
     * 房源管理(销售楼盘 房屋租赁)详情信息
     *
     * @Author: 张dy
     * @Date: 2021/8/16
     * @Param:
     */
    @PostMapping("/findById")
    public TbHouse findById(@RequestParam("id") String id) {
        return houseService.findById(id);
    }

    /**
     * 添加房源信息
     *
     * @Author: lin
     * @Date: 2021/8/16
     * @Param: [want, userId]
     */
    @PostMapping(value = "/addHouse/{userId}/{status}",produces = "text/html")
    @IngoreResponseAdvice
    public String addHouse(@RequestBody TbHouse house,
                         @PathVariable("userId") Long userId,
                         @PathVariable("status") String status) {
        try {
           return houseService.addHouse(house, userId, status);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 修改房源 信息
     *
     * @Author: 张dy
     * @Date: 2021/8/16
     * @Param: [want, userId]
     */
    @PostMapping("/updHouse")
    public void updHouse(@RequestBody TbHouse house) {
        try {
            houseService.updHouse(house);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 房源信息指派经纪人
     *
     * @Author: 张dy
     * @Date: 2021/8/16
     * @Param: [want, userId]
     */
    @GetMapping("/addHouseBroker/{id}/{brokerId}")
    public void addHouseBroker(@PathVariable("id") String id,
                               @PathVariable("brokerId") Long brokerId) {
        try {
            houseService.addHouseBroker(id, brokerId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 租赁房源状态改变
     *
     * @Author: 张dy
     * @Date: 2021/8/16
     * @Param: [want, userId]
     */
    @GetMapping("/updHouseStatus/{id}/{status}")
    public void updHouseStatus(@PathVariable("id") String id,
                               @PathVariable("status") String status) {
        try {
            houseService.updHouseStatus(id, status);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    /**
     * 搜索房源
     */
    @PostMapping("/searchHouse")
    public ResultData searchHouse(@RequestBody HouseSearchVo houseSearchVo) throws IOException {
        return houseService.searchHouse(houseSearchVo);
    }


    @RequestMapping("/updateDeteleById")
    public void updateDeteleById(@RequestParam("id") String id)  {
        houseService.updateDeteleById(id);
    }


    /**
     * 获取经纬度接口
     */

}
